<?php

// TODO this should have a base class, leaving that out because it would make file search more difficult in config_widgets.php
class Widget2 {
  const TITLE_TOKEN = '<!-- widget_title -->';
  const LIST_TOKEN = '<!-- widget_text -->';
  private $output = '';

  function __construct($title = "Widget2",$items = array()) {
    // some of these strings should be moved into a base class and managed using some variable for the file name
    if($s = file_get_contents("templates/Widget2.inc")) {
      if(strpos($s, $this::TITLE_TOKEN) > 0) {
        $s = str_replace($this::TITLE_TOKEN, $title, $s);
      }
      if(strpos($s, $this::LIST_TOKEN)) {
        $tmp = '';
        if(count($items) > 0) {
          foreach($items as $item) {
            $tmp .= "\n".'<li>'.$item.'</li>';
          }
          // only need to replace if there's something to replace with - no need to replace with '' as the token is hidden
          $s = str_replace($this::LIST_TOKEN, $tmp, $s);
        }
      }
      $this->output = $s;
    }
  }

  function to_string() {
    return $this->output;
  }
}
?>
